import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:magic_car/UI/Loading.dart';
import 'package:magic_car/util/HttpHelper.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:toast/toast.dart';

class ChargerPage extends StatefulWidget {
  ChargerPage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<ChargerPage> {
  String paytype = "0";
  String name = "";
  String acount = "";
  String mobile = "";
  String money = "";
  String banckName="";
  //申请提现
  applydraw() async {
    if (name == "" || acount == "" || mobile == "" || money == "") {
      Toast.show("请填写完整的提现信息", context);
      return;
    }
    LoadingPage loadpage = LoadingPage(context);
    loadpage.show();

    Map<String, String> map = new Map();
    SharedPreferences pref = await SharedPreferences.getInstance();
    map["id"] = pref.getString('uid');
    map["name"] = name;
    map["mobile"] = mobile;
    map["account"] = acount;
    map["money"] = money;
    map["bankname"]=banckName;
    map["ispartner"]='1';
    print(map);

    HttpHelper.post(HttpHelper.API_SubDrawApply, (data) async {
      loadpage.close();
      if (data != null) {
        Toast.show(data['msg'], context);
        print(data);
        print(data["info"].length.toString());
        if (data["code"].toString() == "1") {
          setState(() {});
        }
      }
    }, params: map);
  }

  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(
          title: new Text('充值'),
          backgroundColor: Colors.white,
          elevation: 0,
        ),
        body: new Container(
          color: Color.fromRGBO(239, 239, 239, 1),
          child: new ListView(
            children: <Widget>[
              new Padding(
                padding: new EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 15.0),
                child: new Column(
                  children: <Widget>[
                    new Container(
                        color: Colors.white,
                        child: new Column(children: <Widget>[
                          new Padding(
                              padding:
                                  new EdgeInsets.fromLTRB(15.0, 0.0, 15.0, 0.0),
                              child: new Container(
                                height: 50,
                                child: Row(children: <Widget>[
                                  new Text("充值金额"),
                                  Expanded(
                                      child: new TextField(
                                          textAlign: TextAlign.right,
                                          onChanged: (value) {
                                            setState(() {
                                              money = value;
                                            });
                                          },
                                          // controller: _validtroller,
                                          decoration: InputDecoration(
                                            hintText: '请输入充值金额',
                                            border: OutlineInputBorder(
                                              borderSide: BorderSide.none,
                                            ),
                                          )))
                                ]),
                              )),
                          new Container(
                            height: 1,
                            color: Color.fromRGBO(239, 239, 239, 1),
                          ),
                      
                         
                         
                         
                          
                        ])),
                    new Padding(
                        padding: new EdgeInsets.fromLTRB(10, 10, 10, 10),
                        child: Align(
                            alignment: Alignment.centerLeft,
                            child:
                                new Text("单笔支付小于5000.00元，充值的金额可用于报告下载时使用，此充值不可退费",
                                    style: TextStyle(
                                      fontSize: 11,
                                      color: Color.fromRGBO(
                                        153,
                                        153,
                                        153,
                                        1,
                                      ),
                                    )))),
                    new Padding(
                        padding:
                            new EdgeInsets.fromLTRB(20.0, 50.0, 20.0, 10.0),
                        child: new Container(
                          width: double.infinity,
                          height: 40,
                          child: new Material(
                            color: Color.fromRGBO(239, 239, 239, 1),
                            //INK可以实现装饰容器
                            child: new Ink(
                              //用ink圆角矩形
                              // color: Colors.red,
                              decoration: new BoxDecoration(
                                //背景
                                color: Color.fromRGBO(27, 182, 251, 1),
                                //设置四周圆角 角度
                                borderRadius:
                                    BorderRadius.all(Radius.circular(20.0)),
                                //设置四周边框
                                border: new Border.all(
                                    width: 1,
                                    color: Color.fromRGBO(27, 182, 251, 1)),
                              ),
                              child: new InkWell(
                                  //圆角设置,给水波纹也设置同样的圆角
                                  //如果这里不设置就会出现矩形的水波纹效果
                                  borderRadius: new BorderRadius.circular(15.0),

                                  //设置点击事件回调
                                  onTap: () {
                                    applydraw();
                                  },
                                  child: Container(
                                    //设置 child 居中
                                    alignment: Alignment(0, 0),
                                    height: 40,
                                    width: double.infinity,
                                    //color: Color.fromRGBO(27, 182, 251, 1),
                                    child: Text(
                                      "微信支付",
                                      style: TextStyle(color: Colors.white),
                                    ),
                                  )),
                            ),
                          ),
                        )),
                    // Padding(
                    //   padding: new EdgeInsets.fromLTRB(20.0, 0.0, 20.0, 10.0),
                    //   child: new Center(
                    //     child: new FlatButton(
                    //       child: new Text(
                    //         '提现记录',
                    //         style: TextStyle(fontSize: 15),
                    //       ),
                    //       textColor: Color.fromRGBO(27, 182, 251, 1),
                    //       //color: Color.fromRGBO(27, 182, 251, 1),
                    //       onPressed: () {
                    //         //drawrec
                    //         Navigator.pushNamed(context, "drawrec");
                    //       },
                    //     ),
                    //   ),
                    // )
                  ],
                ),
              ),
            ],
          ),
        ));
  }
}
